package com.czz.manage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.czz.manage.entity.Order;
import com.czz.manage.mapper.OrderMapper;
import com.czz.manage.query.OrderQuery;
import com.czz.manage.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

/**
 * @ClassName: OrderServiceImpl
 * @Author Czz
 * @Date 2020/2/17
 * @Time 20:24
 **/
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {

    @Autowired
    OrderMapper orderMapper;

    @Override
    public void getOrderPageList(Page<Order> pageParam, OrderQuery orderQuery) {
        QueryWrapper<Order> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("gmt_create");

        if (!ObjectUtils.isEmpty(orderQuery)){
            orderMapper.selectPage(pageParam,queryWrapper);
        }

        String mobile  = orderQuery.getMobile();
        String courseName = orderQuery.getCourseName();
        String orderId = orderQuery.getOrderId();
        String trade = orderQuery.getTrade();
        Integer status = orderQuery.getStatus();
        String begin = orderQuery.getBegin();
        String end = orderQuery.getEnd();

        if (!StringUtils.isEmpty(mobile)){
            queryWrapper.like("user_mobile",mobile);
        }

        if (!StringUtils.isEmpty(courseName)){
            queryWrapper.like("course_name",courseName);
        }

        if (!StringUtils.isEmpty(orderId)){
            queryWrapper.like("order_id",orderId);
        }

        if (!StringUtils.isEmpty(trade)){
            queryWrapper.like("order_trade",trade);
        }

        if (!StringUtils.isEmpty(status)){
            queryWrapper.eq("order_status",status);
        }

        if (!StringUtils.isEmpty(begin)){
            queryWrapper.ge("gmt_create",begin);
        }

        if (!StringUtils.isEmpty(end)){
            queryWrapper.le("gmt_create",end);
        }

        orderMapper.selectPage(pageParam,queryWrapper);
    }
}
